package com.company;


import com.company.aop.pojo.Account;
import com.company.aop.service.IAccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @date : 2022/3/25 15:25
 */

@ComponentScan("com.company")
public class SpringDemoApplication {


    public static void main(String[] args) {
        // 1.使用ApplicationContext接口，即获取Spring IoC容器
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        // 2.根据bean的id获取对象
//        IAccountService accountService = (IAccountService) context.getBean("accountService");
//        IAccountService myAccountService = (IAccountService) context.getBean("myAccountService");
//        IAccountService accountService2 = (IAccountService) context.getBean("accountService");
//        IAccountDao accountDao = (IAccountDao) context.getBean("accountDao");
        // 3.打印获取到的对象
//        System.out.println(accountService);
//        System.out.println(accountService2);
//        System.out.println(myAccountService);
//        System.out.println(accountDao);


//        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
//        IAccountDao accountDao = (IAccountDao) context.getBean("annotationAccountDaoImpl");
//        IAccountService accountService = (IAccountService) context.getBean("annotationAccountServiceImpl");
//        System.out.println(accountService);
//        System.out.println(accountDao);

//        Account account = new Account();
//        account.setId(2);
//        account.setName("李四");
//        account.setMoney(100.0);


        ApplicationContext context = new AnnotationConfigApplicationContext(SpringDemoApplication.class);
        IAccountService accountService = (IAccountService) context.getBean("accountService");
//        System.out.println(accountService);
        Account account = new Account();
        account.setId(1);
        account.setName("张三");
        account.setMoney(100.0);
        System.out.println(accountService.updateAccount(account));
//        System.out.println(accountService.transfer(1, 2, 100.0));
//        System.out.println(accountService.saveAccount(account));
//        System.out.println(accountService.deleteAccount(1));


//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-aop.xml");
//        IAccountService accountService = (IAccountService) context.getBean("accountService");
//        Account account = new Account();
//        account.setId(1);
//        account.setName("张三");
//        account.setMoney(100.0);
//        System.out.println(accountService.updateAccount(account));
//        System.out.println(accountService.transfer(1, 2, 100.0));

    }
}
